<template>
  <div class="index">
    <el-carousel indicator-position="outside" class="index-banner">
      <el-carousel-item v-for="(item, index) in indexBanner" :key="index" @click="openCarouselLink(item.url)">
        <el-image style="width: 100%; height: 220px" :src="item.pic_url" fit="cover"></el-image>
      </el-carousel-item>
    </el-carousel>
    <div class="news-box">
      <div class="wap-common-title">
        <h1>新闻动态</h1>
        <p>China New Information Consumption Competition News</p>
      </div>
      <div class="news">
        <el-image style="width: 100%; height: 180px" :src="newsImg" fit="cover" @click="openNewsLink()"></el-image>
        <div class="new-list">
          <div class="news-item" v-for="item in newsList" :key="item.id" @click="goDetail('news-show', item.id)">
            <h1 class="one-write">
              {{ item.title }}
            </h1>
            <span>{{
              dayjs(item.created_at * 1000).format("YYYY-MM-DD")
            }}</span>
            <p class="two-write">{{ item.sub_title }}</p>
          </div>
          <h2 class="more-btn" @click="goNewsList()">查看更多 ></h2>
        </div>
      </div>
    </div>
    <div class="match">
      <div class="match-item" v-for="(item, index) in matchList" :key="index" @click="goDetail('match-show', item.id)">
        <div class="item-nav">
          <h1>{{ item.e_one_title }}<br />{{ item.e_two_title }}</h1>
          <p>{{ item.title }}</p>
        </div>
        <el-image style="width: 100%; height: 150px" :src="item.pic_url" fit="cover"></el-image>
      </div>
    </div>
    <div class="works-box">
      <div class="wap-common-title">
        <h1>获奖作品</h1>
        <p>China New Information Consumption Competition News</p>
      </div>
      <el-carousel class="works-card" type="card" height="150px">
        <el-carousel-item v-for="(item, index) in worksList" :key="index">
          <el-image style="width: 100%; height: 100%" :src="item.pic_url" fit="cover"
            @click="goDetail('works-show',item.id)"></el-image>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="gusts-box">
      <div class="wap-common-title">
        <h1>专家观点</h1>
        <p>China New Information Consumption Competition News</p>
      </div>
      <div class="gusts">
        <div class="gusts-item" v-for="(item, index) in indexGuests" :key="index"
          @click="goDetail('news-show', item.id)">
          <el-image style="width: 100%; height: 165px" :src="item.pic_url" fit="cover"></el-image>
          <p class="one-write">{{ item.title }}</p>
        </div>
      </div>
    </div>
    <div class="cooperation-box">
      <div class="wap-common-title">
        <h1>合作伙伴</h1>
        <p>China New Information Consumption Competition News</p>
      </div>
      <div class="cooperation">
        <div class="cooperation-item" v-for="(item, index) in indexCooperations.slice(0, cooperationLength)"
          :key="index">
          <el-image style="width: 100%; height: 54px" :src="item.pic_url" fit="contain"></el-image>
        </div>
      </div>
      <div v-if="cooperationLength != indexCooperations.length" class="more-btn" @click="cooperationMore()">
        查看更多
      </div>
    </div>
  </div>
</template>
<script>
  import {
    mapGetters,
    mapActions
  } from "vuex";
  export default {
    name: "index",
    components: {},
    data() {
      return {
        newsImg: require("@/assets/images/index/news_img.png"),
        cooperationLength: 0,
      };
    },
    mounted() {
      this.init();
    },
    methods: {
      ...mapActions([
        "getIndexSwiper",
        "getWorksList",
        "getIndexPartner",
        "getIndexGuests",
        "getMatchList",
        "getNewsList",
      ]),
      init() {
        this.getIndexSwiper();
        let newsData = {
          per_page: 4,
          page: 1,
          category_id: 1,
        };
        this.getNewsList(newsData);
        this.getMatchList();
        let worksData = {
          per_page: 6,
          page: 1,
        };
        this.getWorksList(worksData);
        this.getIndexGuests();
        this.getIndexPartner().then((res) => {
          this.cooperationLength =
            parseInt(this.indexCooperations.length / 4) * 2;
          if (this.indexCooperations.length < 10) {
            this.cooperationLength = this.indexCooperations.length;
          }
        });
      },
      openCarouselLink(link) {
        if (link) {
          window.open(link, "_blank");
        }
      },
      openNewsLink() {
        this.$router.push({
          name: 'wap-news-show',
          query: {
            id: 74
          },
        });
      },
      goDetail(address, id) {
        this.$router.push({
          name: "wap-" + address,
          query: {
            id: id
          },
        });
      },
      goNewsList() {
        this.$router.push({
          name: "wap-news",
          query: {
            category_id: 1,
            category_name: "赛事动态",
          },
        });
      },
      cooperationMore() {
        this.cooperationLength = this.indexCooperations.length;
      },
    },
    computed: {
      ...mapGetters([
        "indexBanner",
        "worksList",
        "indexGuests",
        "indexCooperations",
        "matchList",
        "newsList",
      ]),
    },
  };
</script>
<style scoped>
  .index-banner {
    height: 220px;
  }

  .index>>>.el-carousel__container {
    height: 220px;
  }

  .index>>>.el-carousel__indicators {
    position: absolute !important;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0px;
  }

  .news-box {
    box-sizing: border-box;
    padding: 30px 15px;
  }

  .news {
    padding-top: 20px;
  }

  .news-item {
    width: 100%;
    box-sizing: border-box;
    padding: 15px 20px;
    background: #f5f5f5;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    margin-bottom: 20px;
  }

  .new-list {
    padding-top: 10px;
  }

  .new-list h1 {
    font-size: 15px;
    color: #333;
  }

  .new-list span {
    font-size: 12px;
    font-family: MicrosoftYaHei;
    font-weight: 400;
    color: #999999;
  }

  .new-list p {
    font-size: 14px;
    font-family: MicrosoftYaHei;
    font-weight: 400;
    color: #666;
    margin-top: 10px;
  }

  .more-btn {
    font-size: 10px;
    font-family: Adobe Heiti Std;
    font-weight: normal;
    color: #0b4696;
    text-align: center;
  }

  .match {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
  }

  .match-item {
    flex: 50%;
    position: relative;
    height: 150px;
  }

  .match-item .item-nav {
    width: 100%;
    box-sizing: border-box;
    color: #fff;
    position: absolute;
    left: 10px;
    bottom: 30px;
    z-index: 2;
  }

  .match-item {
    font-size: 13px;
    line-height: 20px;
    color: #fff;
  }

  .works-box {
    padding-top: 40px;
  }

  .works-card {
    padding-top: 20px;
  }

  .works-box>>>.el-carousel__indicators--outside {
    display: none;
  }

  .works-box>>>.el-carousel__item--card {
    width: 75%;
  }

  .works-box>>>.el-carousel__item {
    left: -12.5%;
  }

  .gusts-box {
    padding: 40px 15px;
    box-sizing: border-box;
  }

  .gusts {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    margin-top: 20px;
  }

  .gusts-item {
    flex: 47%;
    position: relative;
    margin-right: 5%;
    margin-bottom: 15px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0px 2px 10px 0px rgba(0, 0, 255, 0.15);
  }

  .gusts-item:nth-of-type(2n) {
    margin-right: 0;
  }

  .gusts-item p {
    height: 35px;
    line-height: 35px;
    box-sizing: border-box;
    padding: 0 10px;
    font-size: 14px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #333333;
  }

  .cooperation-box {
    background: #f1f4f9;
    padding: 20px 15px;
  }

  .cooperation {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 20px 0px 10px;
  }

  .cooperation-item {
    width: 48%;
    height: 60px;
    box-sizing: border-box;
    padding: 5px;
    background: #fff;
    margin-bottom: 10px;
  }
</style>
